package com.example.speeddating.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.speeddating.annotaion.LoginUser;
import com.example.speeddating.annotaion.TokenCheck;
import com.example.speeddating.common.BaseResponse;
import com.example.speeddating.common.RespGenerator;
import com.example.speeddating.entity.Blacklist;
import com.example.speeddating.entity.TokenEntity;
import com.example.speeddating.enums.ResponseCodeEnum;
import com.example.speeddating.exception.CommonException;
import com.example.speeddating.service.BlacklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 *
 * @author tina
 * @since 2023-08-14 10:32:59
 */
@RestController
public class BlacklistController {

    @Autowired
    private BlacklistService blacklistService;

    @TokenCheck(roles = "user")
    @PostMapping("/user/blacklist/add/{id}")
    public BaseResponse addBlackList(@LoginUser TokenEntity tokenEntity, @PathVariable Long id){
        if (id==null){
            throw new CommonException(ResponseCodeEnum.CODE_600);
        }
        blacklistService.addBlackList(tokenEntity.getId(),id);
        return RespGenerator.returnOK("添加成功");
    }

    @TokenCheck(roles = "user")
    @DeleteMapping("/user/blacklist/remove/{id}")
    public BaseResponse removeBlackList(@LoginUser TokenEntity tokenEntity, @PathVariable Integer id){
        if (id==null){
            throw new CommonException(ResponseCodeEnum.CODE_600);
        }
        blacklistService.removeBlackList(id);
        return RespGenerator.returnOK("移除成功");
    }

    @TokenCheck(roles = "user")
    @GetMapping("/user/blacklist/list")
    public BaseResponse<Page> getBlackList(@LoginUser TokenEntity tokenEntity,@RequestParam(value = "pageSize", defaultValue = "10") int pageSize, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum ){
        Page<Blacklist> list = blacklistService.getBlackList(tokenEntity.getId(),pageNum,pageSize);
        return RespGenerator.returnOK(list);
    }

}
